# Check working directory
getwd()
## [1] "/Users/kbraziun/Documents/data/NEONDI-2016/NEON_group_final/Scripts"
# Load our packages
library(raster)
## Loading required package: sp
library(rgdal)
## rgdal: version: 1.1-10, (SVN revision 622)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 1.11.4, released 2016/01/25
## Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgdal/gdal
## Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
## Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgdal/proj
## Linking to sp version: 1.2-3
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:raster':
##
## intersect, select, union
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(sp)
library(neonAOP)
library(rhdf5)
# install.packages("randomForest")
library(randomForest)
## randomForest 4.6-12
## Type rfNews() to see new features/changes/bug fixes.
##
## Attaching package: 'randomForest'
## The following object is masked from 'package:dplyr':
##
## combine
## The following object is masked from 'package:ggplot2':
##
## margin
# install.packages("party")
library(party)
## Loading required package: grid
## Loading required package: mvtnorm
## Loading required package: modeltools
## Loading required package: stats4
## Loading required package: strucchange
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: sandwich
library(rpart)
setwd("~/Documents/data/NEONDI-2016/NEON_group_final/Scripts/")
Load LiDAR data - CHM, Slope, and Aspect
# Load LiDAR CHM raster
soap_chm<-raster("../../NEONdata/D17-California/SOAP/2013/lidar/SOAP_lidarCHM.tif")
# look at it
hist(soap_chm)
## Warning in .hist1(x, maxpixels = maxpixels, main = main, plot = plot, ...):
## 2% of the raster cells were used. 100000 values used.
summary(soap_chm)
## Warning in .local(object, ...): summary is an estimate based on a sample of 1e+05 cells (2% of all cells)
## SOAP_lidarCHM
## Min. 0.00
## 1st Qu. 0.00
## Median 7.68
## 3rd Qu. 16.78
## Max. 66.67
## NA's 0.00
# Load LiDAR Slope raster
soap_slope<-raster("../../NEONdata/D17-California/SOAP/2013/lidar/SOAP_lidarSlope.tif")
# look at it
hist(soap_slope)
## Warning in .hist1(x, maxpixels = maxpixels, main = main, plot = plot, ...):
## 2% of the raster cells were used. 100000 values used.
summary(soap_slope)
## Warning in .local(object, ...): summary is an estimate based on a sample of 1e+05 cells (2% of all cells)
## SOAP_lidarSlope
## Min. 0.0581632
## 1st Qu. 9.5111072
## Median 14.5188403
## 3rd Qu. 20.2545257
## Max. 76.6572189
## NA's 0.0000000
# Load LiDAR Aspect raster
soap_aspect<-raster("../../NEONdata/D17-California/SOAP/2013/lidar/SOAP_lidarAspect.tif")
# look at it
hist(soap_aspect)
## Warning in .hist1(x, maxpixels = maxpixels, main = main, plot = plot, ...):
## 2% of the raster cells were used. 100000 values used.
summary(soap_aspect)
## Warning in .local(object, ...): summary is an estimate based on a sample of 1e+05 cells (2% of all cells)
## SOAP_lidarAspect
## Min. 0.00000
## 1st Qu. 66.95085
## Median 142.23071
## 3rd Qu. 237.16634
## Max. 359.99759
## NA's 0.00000
# LiDAR data stack
LiDAR.data<-brick(soap_chm,soap_slope,soap_aspect)
Load HI data
# Import the HI data
# In the absence of reflectance, we've got indices
soap_HI_NDVI<-raster("../../NEONdata/D17-California/SOAP/2013/spectrometer/veg_index/SOAP_NDVI.tif")
plot(soap_HI_NDVI)
summary(soap_HI_NDVI)
## Warning in .local(object, ...): summary is an estimate based on a sample of 1e+05 cells (2% of all cells)
## SOAP_NDVI
## Min. -0.4945055
## 1st Qu. 0.7500001
## Median 0.8124461
## 3rd Qu. 0.8431881
## Max. 1.0000000
## NA's 0.0000000
soap_HI_SAVI<-raster("../../NEONdata/D17-California/SOAP/2013/spectrometer/veg_index/SOAP_SAVI.tif")
plot(soap_HI_SAVI)
summary(soap_HI_SAVI)
## Warning in .local(object, ...): summary is an estimate based on a sample of 1e+05 cells (2% of all cells)
## SOAP_SAVI
## Min. -0.05498249
## 1st Qu. 0.36956520
## Median 0.51001653
## 3rd Qu. 0.59896687
## Max. 1.06967282
## NA's 0.00000000
soap_HI_ARVI<-raster("../../NEONdata/D17-California/SOAP/2013/spectrometer/veg_index/SOAP_ARVI.tif")
plot(soap_HI_ARVI)
summary(soap_HI_ARVI)
## Warning in .local(object, ...): summary is an estimate based on a sample of 1e+05 cells (2% of all cells)
## SOAP_ARVI
## Min. -0.6124030
## 1st Qu. 0.6776356
## Median 0.7564782
## 3rd Qu. 0.8010953
## Max. 1.0969793
## NA's 0.0000000
soap_HI_EVI<-raster("../../NEONdata/D17-California/SOAP/2013/spectrometer/veg_index/SOAP_EVI.tif")
plot(soap_HI_EVI)
summary(soap_HI_EVI)
## Warning in .local(object, ...): summary is an estimate based on a sample of 1e+05 cells (2% of all cells)
## SOAP_EVI
## Min. -0.3717282
## 1st Qu. 0.1775352
## Median 0.2537814
## 3rd Qu. 0.3115967
## Max. 13.4057655
## NA's 0.0000000
soap_HI_NDLI<-raster("../../NEONdata/D17-California/SOAP/2013/spectrometer/veg_index/SOAP_NDLI.tif")
plot(soap_HI_NDLI)
summary(soap_HI_NDLI)
## Warning in .local(object, ...): summary is an estimate based on a sample of 1e+05 cells (2% of all cells)
## SOAP_NDLI
## Min. -0.01368532
## 1st Qu. 0.03942865
## Median 0.04882368
## 3rd Qu. 0.05665077
## Max. 37.95143509
## NA's 0.00000000
soap_HI_NDNI<-raster("../../NEONdata/D17-California/SOAP/2013/spectrometer/veg_index/SOAP_NDNI.tif")
plot(soap_HI_NDNI)
summary(soap_HI_NDNI)
## Warning in .local(object, ...): summary is an estimate based on a sample of 1e+05 cells (2% of all cells)
## SOAP_NDNI
## Min. -8.280934e-02
## 1st Qu. 9.710794e-02
## Median 1.195056e-01
## 3rd Qu. 1.378392e-01
## Max. 3.279774e+04
## NA's 0.000000e+00
soap_HI_PRI<-raster("../../NEONdata/D17-California/SOAP/2013/spectrometer/veg_index/SOAP_PRI.tif")
plot(soap_HI_PRI)
summary(soap_HI_PRI)
## Warning in .local(object, ...): summary is an estimate based on a sample of 1e+05 cells (2% of all cells)
## SOAP_PRI
## Min. -0.14775591
## 1st Qu. -0.02857140
## Median -0.01113588
## 3rd Qu. 0.01432662
## Max. 0.22033900
## NA's 0.00000000
# HI data stack
HI.data<-brick(soap_HI_NDVI,soap_HI_SAVI, soap_HI_ARVI, soap_HI_EVI,soap_HI_NDLI, soap_HI_NDNI, soap_HI_PRI)
# Load insitu veg data
# soap_insitu1<-read.csv("../../NEONdata/D17-California/SOAP/2013/insitu/veg-structure/D17_2013_SOAP_vegStr.csv", stringsAsFactors = FALSE)
# we don't need the above because the same info is in the below
soap_insitu<-readOGR("../../NEONdata/D17-California/SOAP/2013/insitu/veg-structure", "soap_stems")
## OGR data source with driver: ESRI Shapefile
## Source: "../../NEONdata/D17-California/SOAP/2013/insitu/veg-structure", layer: "soap_stems"
## with 1231 features
## It has 26 fields
names(soap_insitu)
## [1] "siteid" "sitename" "plotid" "easting" "northing"
## [6] "taxonid" "scientific" "indviduali" "pointid" "individual"
## [11] "individu_1" "dbh" "dbhheight" "basalcanop" "basalcan_1"
## [16] "maxcanopyd" "canopydiam" "stemheight" "stemremark" "stemstatus"
## [21] "canopyform" "livingcano" "inplotcano" "materialsa" "dbhqf"
## [26] "stemmapqf"
str(soap_insitu)
## Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
## ..@ data :'data.frame': 1231 obs. of 26 variables:
## .. ..$ siteid : Factor w/ 1 level "SOAP": 1 1 1 1 1 1 1 1 1 1 ...
## .. ..$ sitename : Factor w/ 1 level "Soaproot Saddle": 1 1 1 1 1 1 1 1 1 1 ...
## .. ..$ plotid : Factor w/ 18 levels "SOAP1343","SOAP139",..: 14 14 14 14 14 14 13 14 13 13 ...
## .. ..$ easting : num [1:1231] 297065 297070 297056 297067 297057 ...
## .. ..$ northing : num [1:1231] 4100725 4100722 4100722 4100719 4100729 ...
## .. ..$ taxonid : Factor w/ 17 levels "ABCO","AMUT",..: 1 1 1 1 1 1 1 1 1 1 ...
## .. ..$ scientific: Factor w/ 16 levels "Abies concolor",..: 1 1 1 1 1 1 1 1 1 1 ...
## .. ..$ indviduali: int [1:1231] 622 632 567 606 639 566 527 638 516 555 ...
## .. ..$ pointid : Factor w/ 5 levels "center","NE",..: 1 2 1 1 1 1 1 1 1 1 ...
## .. ..$ individual: num [1:1231] 5.4 5.4 4.1 8.5 5.7 4.1 8.3 6.9 6.4 6 ...
## .. ..$ individu_1: num [1:1231] 67.8 188.7 250.8 122.4 332.6 ...
## .. ..$ dbh : num [1:1231] 67.6 16.1 5.9 0.9 4 5.1 1.1 3.1 1 8.9 ...
## .. ..$ dbhheight : num [1:1231] 130 130 130 10 130 130 130 130 10 130 ...
## .. ..$ basalcanop: num [1:1231] 8.2 0 0 0 0 0 0 0 0 0 ...
## .. ..$ basalcan_1: num [1:1231] 7.9 0 0 0 0 0 0 0 0 0 ...
## .. ..$ maxcanopyd: num [1:1231] 0 3.3 2.9 0.4 2 2.4 1.3 2 0.5 3 ...
## .. ..$ canopydiam: num [1:1231] 0 3.2 2.8 0.3 1.5 1.9 1.4 1.9 0.5 2.9 ...
## .. ..$ stemheight: num [1:1231] 34.5 13 3.8 0.6 3.4 3 1.4 3.1 0.5 5 ...
## .. ..$ stemremark: Factor w/ 141 levels "0 live hemi",..: NA NA NA NA NA NA NA NA NA NA ...
## .. ..$ stemstatus: Factor w/ 74 levels "1 stem","11 stems",..: NA NA NA NA NA NA NA NA NA NA ...
## .. ..$ canopyform: Factor w/ 5 levels "Cone","Cylinder",..: NA NA NA NA NA NA NA NA NA NA ...
## .. ..$ livingcano: int [1:1231] 100 100 100 100 100 100 100 100 100 100 ...
## .. ..$ inplotcano: int [1:1231] 100 100 100 100 100 100 100 100 100 100 ...
## .. ..$ materialsa: Factor w/ 24 levels "12 stems","f118",..: NA NA NA NA NA NA NA NA NA NA ...
## .. ..$ dbhqf : int [1:1231] 0 0 0 0 0 0 0 0 0 0 ...
## .. ..$ stemmapqf : int [1:1231] 0 1 0 0 0 0 0 0 0 0 ...
## ..@ coords.nrs : num(0)
## ..@ coords : num [1:1231, 1:2] 297065 297070 297056 297067 297057 ...
## .. ..- attr(*, "dimnames")=List of 2
## .. .. ..$ : NULL
## .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
## ..@ bbox : num [1:2, 1:2] 297034 4100083 300153 4101489
## .. ..- attr(*, "dimnames")=List of 2
## .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
## .. .. ..$ : chr [1:2] "min" "max"
## ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
## .. .. ..@ projargs: chr "+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0"
# How many species are there at this site?
length(unique(soap_insitu$taxonid))
## [1] 17
length(unique(soap_insitu$scientific))
## [1] 16
# The data says there are 17 taxonids and 16 spp, so we needed to fix the erroneous taxonid
soap_insitu$taxonid<-gsub("CAIN3", "CEIN3", soap_insitu$taxonid)
# It's fixed! Now there are 16 taxonids and 16 scientific names
# first import the boundaries
index.bounds.flight1 <- read.csv("../index_bounds.csv", sep=",")[,2]
index.bounds.flight2 <- read.csv("../index_bounds2.csv", sep=",")[,2]
flight1 <- "/Volumes/AOP-NEON1-4/D17/SOAP/2013/SOAP_L1/SOAP_Spectrometer/Reflectance/NIS1_20130612_104651_atmcor.h5"
flight2 <- "/Volumes/AOP-NEON1-4/D17/SOAP/2013/SOAP_L1/SOAP_Spectrometer/Reflectance/NIS1_20130612_104000_atmcor.h5"
# thanks to Leah, we know which bands are noisy
# so only importing bands that are not noisy
# grab all bands
bands <- c(1:192,214:282,316:403)
# set epsg
epsg <- 32611
# get stack
all.bands.stack.flight1 <- create_stack(flight1,
bands,
epsg,
subset=TRUE,
dims=index.bounds.flight1)
# get stack
all.bands.stack.flight2 <- create_stack(flight2,
bands,
epsg,
subset=TRUE,
dims=index.bounds.flight2)
# check via plotting to make sure we got the right areas
plot(soap_chm)
plot(all.bands.stack.flight1[[1]], add=TRUE, col="red")
plot(all.bands.stack.flight2[[1]], add=TRUE, col="blue")
# also take a look at the wavelength plots
# get spectra for each band
spectra.flight1 <- extract_av_refl(all.bands.stack.flight1,
aFun = mean)
spectra.flight1 <- as.data.frame(spectra.flight1)
# read in the wavelength information from the HDF5 file
wavelengths<- h5read(flight1, "wavelength")
# convert wavelength to nanometers (nm)
wavelengths <- wavelengths * 1000
spectra.flight1$wavelength <- wavelengths[bands]
# plot spectra
qplot(x=spectra.flight1$wavelength,
y=spectra.flight1$spectra.flight1,
xlab="Wavelength (nm)",
ylab="Reflectance",
main="Spectra for all pixels\nFlight1",
ylim = c(0, .35))
## now flight 2
# get spectra for each band
spectra.flight2 <- extract_av_refl(all.bands.stack.flight2,
aFun = mean)
spectra.flight2 <- as.data.frame(spectra.flight2)
# read in the wavelength information from the HDF5 file
wavelengths<- h5read(flight2, "wavelength")
# convert wavelength to nanometers (nm)
wavelengths <- wavelengths * 1000
spectra.flight2$wavelength <- wavelengths[bands]
wavelengths
## [,1]
## [1,] 382.27
## [2,] 387.28
## [3,] 392.29
## [4,] 397.30
## [5,] 402.31
## [6,] 407.32
## [7,] 412.33
## [8,] 417.34
## [9,] 422.35
## [10,] 427.35
## [11,] 432.36
## [12,] 437.37
## [13,] 442.38
## [14,] 447.39
## [15,] 452.40
## [16,] 457.41
## [17,] 462.42
## [18,] 467.43
## [19,] 472.44
## [20,] 477.45
## [21,] 482.46
## [22,] 487.47
## [23,] 492.48
## [24,] 497.49
## [25,] 502.49
## [26,] 507.50
## [27,] 512.51
## [28,] 517.52
## [29,] 522.53
## [30,] 527.54
## [31,] 532.55
## [32,] 537.56
## [33,] 542.57
## [34,] 547.58
## [35,] 552.59
## [36,] 557.60
## [37,] 562.61
## [38,] 567.62
## [39,] 572.63
## [40,] 577.63
## [41,] 582.64
## [42,] 587.65
## [43,] 592.66
## [44,] 597.67
## [45,] 602.68
## [46,] 607.69
## [47,] 612.70
## [48,] 617.71
## [49,] 622.72
## [50,] 627.73
## [51,] 632.74
## [52,] 637.75
## [53,] 642.76
## [54,] 647.76
## [55,] 652.77
## [56,] 657.78
## [57,] 662.79
## [58,] 667.80
## [59,] 672.81
## [60,] 677.82
## [61,] 682.83
## [62,] 687.84
## [63,] 692.85
## [64,] 697.86
## [65,] 702.87
## [66,] 707.88
## [67,] 712.89
## [68,] 717.90
## [69,] 722.91
## [70,] 727.91
## [71,] 732.92
## [72,] 737.93
## [73,] 742.94
## [74,] 747.95
## [75,] 752.96
## [76,] 757.97
## [77,] 762.98
## [78,] 767.99
## [79,] 773.00
## [80,] 778.01
## [81,] 783.02
## [82,] 788.03
## [83,] 793.04
## [84,] 798.04
## [85,] 803.05
## [86,] 808.06
## [87,] 813.07
## [88,] 818.08
## [89,] 823.09
## [90,] 828.10
## [91,] 833.11
## [92,] 838.12
## [93,] 843.13
## [94,] 848.14
## [95,] 853.15
## [96,] 858.16
## [97,] 863.17
## [98,] 868.18
## [99,] 873.18
## [100,] 878.19
## [101,] 883.20
## [102,] 888.21
## [103,] 893.22
## [104,] 898.23
## [105,] 903.24
## [106,] 908.25
## [107,] 913.26
## [108,] 918.27
## [109,] 923.28
## [110,] 928.29
## [111,] 933.30
## [112,] 938.31
## [113,] 943.32
## [114,] 948.32
## [115,] 953.33
## [116,] 958.34
## [117,] 963.35
## [118,] 968.36
## [119,] 973.37
## [120,] 978.38
## [121,] 983.39
## [122,] 988.40
## [123,] 993.41
## [124,] 998.42
## [125,] 1003.43
## [126,] 1008.44
## [127,] 1013.45
## [128,] 1018.46
## [129,] 1023.47
## [130,] 1028.48
## [131,] 1033.48
## [132,] 1038.49
## [133,] 1043.50
## [134,] 1048.51
## [135,] 1053.52
## [136,] 1058.53
## [137,] 1063.54
## [138,] 1068.55
## [139,] 1073.56
## [140,] 1078.57
## [141,] 1083.58
## [142,] 1088.59
## [143,] 1093.60
## [144,] 1098.61
## [145,] 1103.62
## [146,] 1108.63
## [147,] 1113.63
## [148,] 1118.64
## [149,] 1123.65
## [150,] 1128.66
## [151,] 1133.67
## [152,] 1138.68
## [153,] 1143.69
## [154,] 1148.70
## [155,] 1153.71
## [156,] 1158.72
## [157,] 1163.73
## [158,] 1168.74
## [159,] 1173.75
## [160,] 1178.76
## [161,] 1183.76
## [162,] 1188.77
## [163,] 1193.78
## [164,] 1198.79
## [165,] 1203.80
## [166,] 1208.81
## [167,] 1213.82
## [168,] 1218.83
## [169,] 1223.84
## [170,] 1228.85
## [171,] 1233.86
## [172,] 1238.87
## [173,] 1243.88
## [174,] 1248.89
## [175,] 1253.90
## [176,] 1258.90
## [177,] 1263.91
## [178,] 1268.92
## [179,] 1273.93
## [180,] 1278.94
## [181,] 1283.95
## [182,] 1288.96
## [183,] 1293.97
## [184,] 1298.98
## [185,] 1303.99
## [186,] 1309.00
## [187,] 1314.01
## [188,] 1319.02
## [189,] 1324.03
## [190,] 1329.03
## [191,] 1334.04
## [192,] 1339.05
## [193,] 1344.06
## [194,] 1349.07
## [195,] 1354.08
## [196,] 1359.09
## [197,] 1364.10
## [198,] 1369.11
## [199,] 1374.12
## [200,] 1379.13
## [201,] 1384.14
## [202,] 1389.15
## [203,] 1394.16
## [204,] 1399.17
## [205,] 1404.18
## [206,] 1409.18
## [207,] 1414.19
## [208,] 1419.20
## [209,] 1424.21
## [210,] 1429.22
## [211,] 1434.23
## [212,] 1439.24
## [213,] 1444.25
## [214,] 1449.26
## [215,] 1454.27
## [216,] 1459.28
## [217,] 1464.29
## [218,] 1469.30
## [219,] 1474.31
## [220,] 1479.32
## [221,] 1484.32
## [222,] 1489.33
## [223,] 1494.34
## [224,] 1499.35
## [225,] 1504.36
## [226,] 1509.37
## [227,] 1514.38
## [228,] 1519.39
## [229,] 1524.40
## [230,] 1529.41
## [231,] 1534.42
## [232,] 1539.43
## [233,] 1544.44
## [234,] 1549.45
## [235,] 1554.46
## [236,] 1559.47
## [237,] 1564.48
## [238,] 1569.48
## [239,] 1574.49
## [240,] 1579.50
## [241,] 1584.51
## [242,] 1589.52
## [243,] 1594.53
## [244,] 1599.54
## [245,] 1604.55
## [246,] 1609.56
## [247,] 1614.57
## [248,] 1619.58
## [249,] 1624.59
## [250,] 1629.60
## [251,] 1634.60
## [252,] 1639.61
## [253,] 1644.62
## [254,] 1649.63
## [255,] 1654.64
## [256,] 1659.65
## [257,] 1664.66
## [258,] 1669.67
## [259,] 1674.68
## [260,] 1679.69
## [261,] 1684.70
## [262,] 1689.71
## [263,] 1694.72
## [264,] 1699.73
## [265,] 1704.74
## [266,] 1709.74
## [267,] 1714.75
## [268,] 1719.76
## [269,] 1724.77
## [270,] 1729.78
## [271,] 1734.79
## [272,] 1739.80
## [273,] 1744.81
## [274,] 1749.82
## [275,] 1754.83
## [276,] 1759.84
## [277,] 1764.85
## [278,] 1769.86
## [279,] 1774.87
## [280,] 1779.88
## [281,] 1784.88
## [282,] 1789.89
## [283,] 1794.90
## [284,] 1799.91
## [285,] 1804.92
## [286,] 1809.93
## [287,] 1814.94
## [288,] 1819.95
## [289,] 1824.96
## [290,] 1829.97
## [291,] 1834.98
## [292,] 1839.99
## [293,] 1845.00
## [294,] 1850.01
## [295,] 1855.01
## [296,] 1860.02
## [297,] 1865.03
## [298,] 1870.04
## [299,] 1875.05
## [300,] 1880.06
## [301,] 1885.07
## [302,] 1890.08
## [303,] 1895.09
## [304,] 1900.10
## [305,] 1905.11
## [306,] 1910.12
## [307,] 1915.13
## [308,] 1920.14
## [309,] 1925.15
## [310,] 1930.15
## [311,] 1935.16
## [312,] 1940.17
## [313,] 1945.18
## [314,] 1950.19
## [315,] 1955.20
## [316,] 1960.21
## [317,] 1965.22
## [318,] 1970.23
## [319,] 1975.24
## [320,] 1980.25
## [321,] 1985.26
## [322,] 1990.27
## [323,] 1995.28
## [324,] 2000.29
## [325,] 2005.30
## [326,] 2010.30
## [327,] 2015.31
## [328,] 2020.32
## [329,] 2025.33
## [330,] 2030.34
## [331,] 2035.35
## [332,] 2040.36
## [333,] 2045.37
## [334,] 2050.38
## [335,] 2055.39
## [336,] 2060.40
## [337,] 2065.41
## [338,] 2070.42
## [339,] 2075.42
## [340,] 2080.44
## [341,] 2085.44
## [342,] 2090.45
## [343,] 2095.46
## [344,] 2100.47
## [345,] 2105.48
## [346,] 2110.49
## [347,] 2115.50
## [348,] 2120.51
## [349,] 2125.52
## [350,] 2130.53
## [351,] 2135.54
## [352,] 2140.55
## [353,] 2145.56
## [354,] 2150.57
## [355,] 2155.58
## [356,] 2160.58
## [357,] 2165.59
## [358,] 2170.60
## [359,] 2175.61
## [360,] 2180.62
## [361,] 2185.63
## [362,] 2190.64
## [363,] 2195.65
## [364,] 2200.66
## [365,] 2205.67
## [366,] 2210.68
## [367,] 2215.69
## [368,] 2220.70
## [369,] 2225.70
## [370,] 2230.72
## [371,] 2235.72
## [372,] 2240.73
## [373,] 2245.74
## [374,] 2250.75
## [375,] 2255.76
## [376,] 2260.77
## [377,] 2265.78
## [378,] 2270.79
## [379,] 2275.80
## [380,] 2280.81
## [381,] 2285.82
## [382,] 2290.83
## [383,] 2295.84
## [384,] 2300.84
## [385,] 2305.86
## [386,] 2310.86
## [387,] 2315.87
## [388,] 2320.88
## [389,] 2325.89
## [390,] 2330.90
## [391,] 2335.91
## [392,] 2340.92
## [393,] 2345.93
## [394,] 2350.94
## [395,] 2355.95
## [396,] 2360.96
## [397,] 2365.97
## [398,] 2370.98
## [399,] 2375.99
## [400,] 2381.00
## [401,] 2386.00
## [402,] 2391.01
## [403,] 2396.02
## [404,] 2401.03
## [405,] 2406.04
## [406,] 2411.05
## [407,] 2416.06
## [408,] 2421.07
## [409,] 2426.08
## [410,] 2431.09
## [411,] 2436.10
## [412,] 2441.11
## [413,] 2446.12
## [414,] 2451.12
## [415,] 2456.14
## [416,] 2461.14
## [417,] 2466.15
## [418,] 2471.16
## [419,] 2476.17
## [420,] 2481.18
## [421,] 2486.19
## [422,] 2491.20
## [423,] 2496.21
## [424,] 2501.22
## [425,] 2506.23
## [426,] 2511.24
# plot spectra
qplot(x=spectra.flight2$wavelength,
y=spectra.flight2$spectra.flight2,
xlab="Wavelength (nm)",
ylab="Reflectance",
main="Spectra for all pixels\nFlight 2",
ylim = c(0, .35))
### Braziunas ends here
HI.LiDAR.data<-stack(HI.data, LiDAR.data)
# write a function to compare extents and crop layers if they are different
same_extent<-function(raster1, raster2) {
if (extent(raster1)==extent(raster2)) {
print("Rasters have same extent")
} else {
overlap<-raster::intersect(extent(raster1), extent(raster2))
# crop both rasters
# might be good to check which is bigger and compare
print("Extents are different, Cropping data")
raster1<-crop(raster1, overlap)
raster2<-crop(raster2, overlap)
# create a stack of the new rasters
}
raster.stack<-stack(raster1, raster2)
return(raster.stack)
}
overlap<-raster::intersect(extent(HI.LiDAR.data), extent(all.bands.stack.flight1))
HI.LiDAR.data<-crop(HI.LiDAR.data, overlap)
# test this
same_extent(HI.LiDAR.data, all.bands.stack.flight1)
## [1] "Rasters have same extent"
## class : RasterStack
## dimensions : 841, 103, 86623, 359 (nrow, ncol, ncell, nlayers)
## resolution : 1, 1 (x, y)
## extent : 297029, 297132, 4100078, 4100919 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=utm +zone=11 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
## names : SOAP_NDVI, SOAP_SAVI, SOAP_ARVI, SOAP_EVI, SOAP_NDLI, SOAP_NDNI, SOAP_PRI, SOAP_lidarCHM, SOAP_lidarSlope, SOAP_lidarAspect, nm_382, nm_387, nm_392, nm_397, nm_402, ...
## min values : 0.053279366, 0.044161085, -0.072281204, 0.020963496, -0.006858835, 0.023170736, -0.105882332, 0.000000000, 0.028863961, 0.000000000, 0.000000000, 0.000000000, 0.001300000, 0.001600000, 0.000000000, ...
## max values : 0.9348089, 1.0646397, 0.9507247, 11.8180132, 113.1278076, 3272.6945801, 0.1898734, 58.7500000, 39.2577286, 359.9960022, 0.1309000, 0.1492000, 0.1797000, 0.1847000, 0.1611000, ...
all.data3<-stack(HI.LiDAR.data, all.bands.stack.flight1)
# check our data
all.data<-all.data3
# no NAs in this dataframe
# Get just the stems that are in flight 1
stems_flight1<-raster::intersect(soap_insitu, all.data)
# ?intersect
# Should we sample at 1m pixel or take neighbors? Look at crown diameter stats to decide
summary(stems_flight1$maxcanopyd)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 0.000 0.650 1.400 2.018 2.600 30.000 1
# Mean (2.34) and median (1.6) max canopy diameter is over 1m, so sample larger that 1m cell. Create buffers for maxcanopyd/2 for each stem
#The buffer can be specified as a single value, or as a vector of the length of the number of points
buffers<-(stems_flight1$maxcanopyd)/2
# sample buffer specific to mean crown width. The small argument returns a number even if the buffer doesn't include a cell center. Use the mean function so if the buffer includes multiple cells, it will take mean value of those cells.
# sampled_points<-extract(all.data, soap_insitu, buffer=buffers, small=TRUE, fun=mean, na.rm=TRUE)
# Error: Error in apply(x, 2, fun2) : dim(X) must have a positive length
# work-around for the error that happens above
sampled_points1<-extract(all.data, stems_flight1, buffer=buffers, small=TRUE)
# The below workaround didn't work:
# sampled_points2<-lapply(sampled_points1, function(x) ifelse(is.matrix(x), colMeans(x), x))
# sampled_points<-do.call(rbind, sampled_points2)
# install.packages("plyr")
library("plyr")
## -------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## -------------------------------------------------------------------------
##
## Attaching package: 'plyr'
## The following object is masked from 'package:modeltools':
##
## empty
## The following objects are masked from 'package:dplyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
results.df <- as.data.frame(t(sampled_points1[[1]]))
for (i in 2:length(sampled_points1)) {
if (is.matrix(sampled_points1[[i]])) {
row.result <- as.data.frame(t(colMeans(sampled_points1[[i]])))
} else {
row.result <- as.data.frame(t(sampled_points1[[i]]))
}
results.df <- rbind(results.df, row.result)
}
# combine
sampled_points<-cbind(results.df,stems_flight1$taxonid)
head(sampled_points)
## SOAP_NDVI SOAP_SAVI SOAP_ARVI SOAP_EVI SOAP_NDLI SOAP_NDNI
## 1 0.7633886 0.5164691 0.6877912 0.2647978 0.04575786 0.09593088
## 2 0.7578541 0.3185709 0.6863649 0.1404254 0.03756584 0.09267312
## 3 0.7876813 0.3520562 0.7207722 0.1600581 0.03858912 0.09930303
## 4 0.7286226 0.3069898 0.6539162 0.1324275 0.03105079 0.08657276
## 5 0.8217758 0.4782195 0.7644735 0.2214587 0.04483297 0.11717684
## 6 0.8207526 0.3602602 0.7623493 0.1534571 0.03847604 0.09553890
## SOAP_PRI SOAP_lidarCHM SOAP_lidarSlope SOAP_lidarAspect nm_382
## 1 -0.041450772 31.959999 2.354810 206.1087 0.01330000
## 2 -0.019094033 13.496666 3.149477 100.8364 0.01097778
## 3 -0.007491713 5.585714 2.304181 187.3182 0.01057143
## 4 -0.037037034 3.190000 5.761685 124.4639 0.00390000
## 5 0.010480136 12.030000 3.287421 178.3113 0.02160000
## 6 -0.007618393 9.030000 2.455193 157.8280 0.00756000
## nm_387 nm_392 nm_397 nm_402 nm_407 nm_412
## 1 0.01290000 0.01900000 0.01560000 0.01030000 0.011700000 0.011000000
## 2 0.01303333 0.01750000 0.01474444 0.01050000 0.010977778 0.011833333
## 3 0.01190000 0.01302857 0.01294286 0.00720000 0.007271429 0.008771429
## 4 0.00680000 0.00740000 0.00710000 0.00450000 0.002900000 0.003900000
## 5 0.02353333 0.02866667 0.02793333 0.02046667 0.021866667 0.022933333
## 6 0.01094000 0.01216000 0.01238000 0.00666000 0.006840000 0.007860000
## nm_417 nm_422 nm_427 nm_432 nm_437 nm_442
## 1 0.012400000 0.01260000 0.01680000 0.01600000 0.01680000 0.01910000
## 2 0.013022222 0.01491111 0.01712222 0.01760000 0.01751111 0.01940000
## 3 0.009257143 0.01094286 0.01292857 0.01285714 0.01252857 0.01410000
## 4 0.003700000 0.00540000 0.00640000 0.00640000 0.00520000 0.00680000
## 5 0.025233333 0.02840000 0.03196667 0.03286667 0.03360000 0.03716667
## 6 0.008680000 0.00964000 0.01208000 0.01178000 0.01120000 0.01272000
## nm_447 nm_452 nm_457 nm_462 nm_467 nm_472
## 1 0.01830000 0.01810000 0.01880000 0.02020000 0.01930000 0.02000000
## 2 0.01948889 0.01954444 0.01984444 0.02135556 0.02092222 0.02073333
## 3 0.01392857 0.01364286 0.01367143 0.01482857 0.01434286 0.01394286
## 4 0.00530000 0.00500000 0.00570000 0.00580000 0.00630000 0.00530000
## 5 0.03716667 0.03586667 0.03783333 0.04040000 0.03930000 0.03883333
## 6 0.01246000 0.01216000 0.01180000 0.01302000 0.01234000 0.01196000
## nm_477 nm_482 nm_487 nm_492 nm_497 nm_502
## 1 0.02010000 0.02030000 0.02110000 0.02010000 0.02060000 0.02210000
## 2 0.02170000 0.02146667 0.02251111 0.02273333 0.02281111 0.02426667
## 3 0.01538571 0.01495714 0.01572857 0.01528571 0.01560000 0.01690000
## 4 0.00650000 0.00570000 0.00640000 0.00550000 0.00540000 0.00650000
## 5 0.04050000 0.04093333 0.04220000 0.04243333 0.04370000 0.04566667
## 6 0.01312000 0.01304000 0.01370000 0.01332000 0.01342000 0.01446000
## nm_507 nm_513 nm_518 nm_523 nm_528 nm_533
## 1 0.02400000 0.02630000 0.02830000 0.02940000 0.03290000 0.03510000
## 2 0.02571111 0.02821111 0.03037778 0.03207778 0.03555556 0.03815556
## 3 0.01805714 0.02044286 0.02334286 0.02468571 0.02875714 0.03121429
## 4 0.00600000 0.00680000 0.00660000 0.00690000 0.00720000 0.00810000
## 5 0.04886667 0.05446667 0.06120000 0.06686667 0.07623333 0.08453333
## 6 0.01534000 0.01688000 0.01906000 0.01984000 0.02320000 0.02486000
## nm_538 nm_543 nm_548 nm_553 nm_558 nm_563
## 1 0.03600000 0.03830000 0.03820000 0.03970000 0.04150000 0.03850000
## 2 0.03982222 0.04146667 0.04174444 0.04252222 0.04445556 0.04261111
## 3 0.03288571 0.03418571 0.03428571 0.03544286 0.03647143 0.03462857
## 4 0.00720000 0.00860000 0.00800000 0.00810000 0.00830000 0.00760000
## 5 0.08970000 0.09430000 0.09560000 0.09833333 0.10246667 0.09673333
## 6 0.02596000 0.02666000 0.02672000 0.02750000 0.02854000 0.02740000
## nm_568 nm_573 nm_578 nm_583 nm_588 nm_593
## 1 0.03820000 0.03680000 0.03630000 0.03610000 0.03500000 0.03440000
## 2 0.04100000 0.04034444 0.03993333 0.03941111 0.03844444 0.03777778
## 3 0.03270000 0.03110000 0.03042857 0.02932857 0.02792857 0.02722857
## 4 0.00760000 0.00780000 0.00760000 0.00750000 0.00710000 0.00790000
## 5 0.09283333 0.08966667 0.08736667 0.08510000 0.08186667 0.08056667
## 6 0.02542000 0.02418000 0.02412000 0.02284000 0.02218000 0.02202000
## nm_598 nm_603 nm_608 nm_613 nm_618 nm_623
## 1 0.03390000 0.03390000 0.03340000 0.03350000 0.03370000 0.03140000
## 2 0.03732222 0.03775556 0.03747778 0.03712222 0.03715556 0.03592222
## 3 0.02728571 0.02671429 0.02680000 0.02630000 0.02588571 0.02464286
## 4 0.00740000 0.00720000 0.00740000 0.00750000 0.00780000 0.00770000
## 5 0.07863333 0.07890000 0.07833333 0.07643333 0.07473333 0.07220000
## 6 0.02156000 0.02122000 0.02172000 0.02150000 0.02086000 0.02034000
## nm_628 nm_633 nm_638 nm_643 nm_648 nm_653
## 1 0.03210000 0.03180000 0.03160000 0.03170000 0.03010000 0.02890000
## 2 0.03563333 0.03625556 0.03621111 0.03594444 0.03512222 0.03397778
## 3 0.02468571 0.02452857 0.02425714 0.02372857 0.02307143 0.02205714
## 4 0.00750000 0.00790000 0.00710000 0.00750000 0.00750000 0.00740000
## 5 0.07136667 0.07100000 0.07080000 0.06866667 0.06596667 0.06356667
## 6 0.02008000 0.02000000 0.02022000 0.02000000 0.01954000 0.01884000
## nm_658 nm_663 nm_668 nm_673 nm_678 nm_683
## 1 0.02870000 0.02780000 0.02620000 0.02670000 0.02550000 0.02590000
## 2 0.03378889 0.03255556 0.03158889 0.03152222 0.03101111 0.03221111
## 3 0.02201429 0.02084286 0.02021429 0.02118571 0.01961429 0.02078571
## 4 0.00810000 0.00730000 0.00740000 0.00740000 0.00620000 0.00740000
## 5 0.06120000 0.05760000 0.05563333 0.05493333 0.05363333 0.05606667
## 6 0.01866000 0.01842000 0.01760000 0.01888000 0.01736000 0.01848000
## nm_688 nm_693 nm_698 nm_703 nm_708 nm_713
## 1 0.03030000 0.03620000 0.04430000 0.05510000 0.06510000 0.07790000
## 2 0.03655556 0.04237778 0.05158889 0.06270000 0.07567778 0.08900000
## 3 0.02427143 0.02957143 0.03865714 0.05058571 0.06404286 0.07814286
## 4 0.00840000 0.00830000 0.00910000 0.01120000 0.01340000 0.01580000
## 5 0.06553333 0.08133333 0.10616667 0.13696667 0.17100000 0.20433333
## 6 0.02144000 0.02502000 0.03114000 0.03958000 0.04968000 0.05918000
## nm_718 nm_723 nm_728 nm_733 nm_738 nm_743 nm_748
## 1 0.08790000 0.1038000 0.1205000 0.1400000 0.1565000 0.1712000 0.1825000
## 2 0.09968889 0.1173778 0.1347444 0.1535000 0.1696889 0.1824111 0.1922889
## 3 0.09080000 0.1101286 0.1277000 0.1478571 0.1633429 0.1765571 0.1850571
## 4 0.01760000 0.0210000 0.0234000 0.0279000 0.0301000 0.0339000 0.0360000
## 5 0.23096667 0.2742000 0.3120000 0.3552000 0.3878000 0.4152667 0.4349333
## 6 0.06830000 0.0821400 0.0941000 0.1083800 0.1186200 0.1271800 0.1343000
## nm_753 nm_758 nm_763 nm_768 nm_773 nm_778 nm_783
## 1 0.1906000 0.1885000 0.2088000 0.2072000 0.2063000 0.2106000 0.2128000
## 2 0.1982333 0.1966556 0.2144000 0.2158111 0.2129111 0.2152778 0.2174111
## 3 0.1911571 0.1902286 0.2070286 0.2063000 0.2058429 0.2080714 0.2095143
## 4 0.0366000 0.0374000 0.0448000 0.0414000 0.0406000 0.0411000 0.0409000
## 5 0.4473667 0.4412667 0.4709000 0.4756333 0.4754667 0.4786000 0.4823667
## 6 0.1373600 0.1356200 0.1530800 0.1492200 0.1481600 0.1500400 0.1511800
## nm_788 nm_793 nm_798 nm_803 nm_808 nm_813 nm_818
## 1 0.2119000 0.2129000 0.2150000 0.2152000 0.2170000 0.2109000 0.2129000
## 2 0.2175333 0.2172111 0.2183556 0.2189333 0.2202000 0.2145667 0.2155778
## 3 0.2104000 0.2095286 0.2092714 0.2105286 0.2123429 0.2081857 0.2076857
## 4 0.0421000 0.0418000 0.0423000 0.0428000 0.0439000 0.0432000 0.0430000
## 5 0.4809333 0.4807000 0.4830333 0.4841000 0.4843333 0.4718000 0.4719000
## 6 0.1516200 0.1508400 0.1514400 0.1519800 0.1531200 0.1499200 0.1519200
## nm_823 nm_828 nm_833 nm_838 nm_843 nm_848 nm_853
## 1 0.2148000 0.2176000 0.2216000 0.2229000 0.2252000 0.2281000 0.2331000
## 2 0.2180667 0.2198000 0.2219778 0.2264778 0.2280667 0.2316889 0.2362222
## 3 0.2090286 0.2121000 0.2134857 0.2187000 0.2198000 0.2240000 0.2280571
## 4 0.0442000 0.0443000 0.0443000 0.0448000 0.0452000 0.0473000 0.0485000
## 5 0.4764000 0.4822333 0.4847667 0.4940000 0.5011333 0.5061667 0.5154000
## 6 0.1515600 0.1542400 0.1553800 0.1585200 0.1595600 0.1630400 0.1648800
## nm_858 nm_863 nm_868 nm_873 nm_878 nm_883 nm_888
## 1 0.2296000 0.2320000 0.2365000 0.2313000 0.2319000 0.2282000 0.2306000
## 2 0.2338889 0.2359889 0.2406667 0.2351333 0.2344556 0.2358111 0.2352000
## 3 0.2257429 0.2280571 0.2322857 0.2273571 0.2280571 0.2283429 0.2280143
## 4 0.0489000 0.0488000 0.0504000 0.0485000 0.0483000 0.0488000 0.0488000
## 5 0.5095333 0.5142667 0.5231000 0.5134000 0.5127333 0.5120333 0.5105667
## 6 0.1646000 0.1657800 0.1689200 0.1646600 0.1661400 0.1659600 0.1663000
## nm_893 nm_898 nm_903 nm_908 nm_913 nm_918 nm_923
## 1 0.2223000 0.2176000 0.2205000 0.2218000 0.2157000 0.2138000 0.2125000
## 2 0.2283556 0.2219889 0.2266333 0.2285222 0.2223444 0.2219000 0.2214778
## 3 0.2211571 0.2158857 0.2209143 0.2221429 0.2157571 0.2160286 0.2167714
## 4 0.0476000 0.0480000 0.0478000 0.0492000 0.0484000 0.0478000 0.0475000
## 5 0.4965667 0.4809333 0.4907000 0.4963000 0.4800333 0.4804000 0.4826667
## 6 0.1607600 0.1579800 0.1616400 0.1624200 0.1578000 0.1590400 0.1582800
## nm_928 nm_933 nm_938 nm_943 nm_948 nm_953 nm_958
## 1 0.1981000 0.1828000 0.1879000 0.1806000 0.1824000 0.1781000 0.1734000
## 2 0.2062111 0.1889111 0.1959667 0.1889667 0.1912333 0.1881778 0.1884889
## 3 0.2024000 0.1893429 0.1942000 0.1881714 0.1907714 0.1881857 0.1900571
## 4 0.0470000 0.0474000 0.0484000 0.0452000 0.0459000 0.0445000 0.0431000
## 5 0.4477000 0.4055000 0.4186667 0.4088333 0.4123333 0.4084667 0.4101000
## 6 0.1480800 0.1405200 0.1461400 0.1394200 0.1424200 0.1403200 0.1420200
## nm_963 nm_968 nm_973 nm_978 nm_983 nm_988 nm_993
## 1 0.1764000 0.1854000 0.1835000 0.1860000 0.1919000 0.1942000 0.1997000
## 2 0.1951889 0.2041556 0.2032111 0.2070222 0.2134667 0.2163111 0.2212000
## 3 0.1963143 0.2047429 0.2040714 0.2085571 0.2148000 0.2176286 0.2216143
## 4 0.0455000 0.0448000 0.0453000 0.0456000 0.0468000 0.0480000 0.0495000
## 5 0.4279667 0.4493000 0.4477000 0.4571667 0.4706333 0.4795667 0.4872333
## 6 0.1468200 0.1528000 0.1509000 0.1545600 0.1592800 0.1616000 0.1649600
## nm_998 nm_1003 nm_1008 nm_1013 nm_1018 nm_1023 nm_1028
## 1 0.2018000 0.2022000 0.2070000 0.2109000 0.2149000 0.2203000 0.2234000
## 2 0.2234778 0.2237222 0.2272889 0.2321000 0.2342889 0.2375222 0.2412000
## 3 0.2241143 0.2234857 0.2270143 0.2308857 0.2335000 0.2366571 0.2399857
## 4 0.0490000 0.0497000 0.0514000 0.0520000 0.0524000 0.0530000 0.0549000
## 5 0.4912667 0.4903333 0.4991000 0.5074000 0.5116000 0.5177667 0.5236000
## 6 0.1658000 0.1670400 0.1690600 0.1711600 0.1730400 0.1751200 0.1781000
## nm_1033 nm_1038 nm_1043 nm_1049 nm_1054 nm_1059 nm_1064
## 1 0.2242000 0.2300000 0.2297000 0.2329000 0.2341000 0.2380000 0.2390000
## 2 0.2422444 0.2453889 0.2474889 0.2498444 0.2518889 0.2540000 0.2546667
## 3 0.2400286 0.2432571 0.2444429 0.2470571 0.2479286 0.2488714 0.2511429
## 4 0.0562000 0.0559000 0.0566000 0.0564000 0.0588000 0.0592000 0.0587000
## 5 0.5258667 0.5310333 0.5349000 0.5379000 0.5414333 0.5427000 0.5463667
## 6 0.1785200 0.1799800 0.1813800 0.1827800 0.1839000 0.1846200 0.1863800
## nm_1069 nm_1074 nm_1079 nm_1084 nm_1089 nm_1094 nm_1099
## 1 0.2411000 0.2400000 0.2385000 0.2365000 0.2367000 0.2315000 0.2233000
## 2 0.2558000 0.2559778 0.2536889 0.2508444 0.2499444 0.2459889 0.2385667
## 3 0.2522000 0.2510571 0.2484714 0.2471143 0.2464143 0.2434286 0.2351429
## 4 0.0599000 0.0595000 0.0602000 0.0584000 0.0590000 0.0579000 0.0565000
## 5 0.5470667 0.5458000 0.5420667 0.5358667 0.5339667 0.5243667 0.5091333
## 6 0.1869800 0.1871800 0.1847200 0.1839600 0.1830600 0.1808200 0.1754000
## nm_1104 nm_1109 nm_1114 nm_1119 nm_1124 nm_1129 nm_1134
## 1 0.2185000 0.2123000 0.1945000 0.1725000 0.1693000 0.1655000 0.1668000
## 2 0.2332778 0.2268333 0.2070333 0.1852333 0.1788222 0.1790000 0.1811778
## 3 0.2312000 0.2257286 0.2066286 0.1865429 0.1812857 0.1810714 0.1842571
## 4 0.0563000 0.0551000 0.0511000 0.0507000 0.0516000 0.0484000 0.0495000
## 5 0.4989333 0.4838667 0.4442667 0.3918667 0.3770333 0.3811667 0.3850000
## 6 0.1723800 0.1688400 0.1546600 0.1419800 0.1392800 0.1398600 0.1415000
## nm_1139 nm_1144 nm_1149 nm_1154 nm_1159 nm_1164 nm_1169
## 1 0.1632000 0.1394000 0.1370000 0.1365000 0.1407000 0.1384000 0.1420000
## 2 0.1841111 0.1589667 0.1599778 0.1631889 0.1691667 0.1714222 0.1746111
## 3 0.1890429 0.1639143 0.1654429 0.1692429 0.1763714 0.1790286 0.1825714
## 4 0.0468000 0.0432000 0.0425000 0.0422000 0.0427000 0.0421000 0.0424000
## 5 0.3984000 0.3475000 0.3479000 0.3600000 0.3761333 0.3840667 0.3901000
## 6 0.1440600 0.1257200 0.1281600 0.1316200 0.1358800 0.1384000 0.1407600
## nm_1174 nm_1179 nm_1184 nm_1189 nm_1194 nm_1199 nm_1204
## 1 0.1416000 0.1385000 0.1379000 0.1370000 0.1387000 0.1359000 0.1335000
## 2 0.1753556 0.1754556 0.1713000 0.1727778 0.1747000 0.1714111 0.1722778
## 3 0.1827286 0.1831000 0.1800714 0.1822571 0.1832857 0.1807571 0.1807000
## 4 0.0421000 0.0434000 0.0420000 0.0412000 0.0420000 0.0419000 0.0417000
## 5 0.3931333 0.3934000 0.3839000 0.3870333 0.3932333 0.3850667 0.3863667
## 6 0.1417200 0.1415800 0.1392600 0.1414600 0.1426800 0.1405200 0.1408400
## nm_1209 nm_1214 nm_1219 nm_1224 nm_1229 nm_1234 nm_1239
## 1 0.1400000 0.1418000 0.1466000 0.1498000 0.1540000 0.1573000 0.1597000
## 2 0.1755111 0.1790778 0.1842778 0.1880778 0.1928889 0.1976889 0.2008222
## 3 0.1841286 0.1878286 0.1920571 0.1971571 0.2008286 0.2062286 0.2078143
## 4 0.0426000 0.0442000 0.0447000 0.0463000 0.0476000 0.0496000 0.0498000
## 5 0.3912333 0.3990333 0.4110667 0.4181000 0.4267333 0.4354667 0.4419333
## 6 0.1435000 0.1462200 0.1498200 0.1535800 0.1565000 0.1599400 0.1614800
## nm_1244 nm_1249 nm_1254 nm_1259 nm_1264 nm_1269 nm_1274
## 1 0.1621000 0.1651000 0.1655000 0.1658000 0.1695000 0.1713000 0.1701000
## 2 0.2024000 0.2052222 0.2066333 0.2072111 0.2082889 0.2132111 0.2124222
## 3 0.2096000 0.2125143 0.2146000 0.2139571 0.2159286 0.2211714 0.2196286
## 4 0.0516000 0.0516000 0.0523000 0.0522000 0.0543000 0.0554000 0.0550000
## 5 0.4446333 0.4502000 0.4527333 0.4559000 0.4560000 0.4650000 0.4629000
## 6 0.1625000 0.1643800 0.1665200 0.1661600 0.1675000 0.1724200 0.1713600
## nm_1279 nm_1284 nm_1289 nm_1294 nm_1299 nm_1304 nm_1309
## 1 0.1678000 0.1686000 0.1658000 0.1637000 0.1589000 0.1545000 0.1463000
## 2 0.2092667 0.2096667 0.2075222 0.2045000 0.2011667 0.1938778 0.1880667
## 3 0.2177000 0.2176286 0.2146714 0.2127143 0.2090571 0.2031714 0.1959286
## 4 0.0549000 0.0551000 0.0544000 0.0536000 0.0538000 0.0522000 0.0485000
## 5 0.4580000 0.4559667 0.4529000 0.4467667 0.4402333 0.4259000 0.4151333
## 6 0.1692400 0.1701800 0.1671800 0.1655200 0.1633400 0.1590000 0.1538800
## nm_1314 nm_1319 nm_1324 nm_1329 nm_1334 nm_1339 nm_1449
## 1 0.1389000 0.1336000 0.1255000 0.1111000 0.1068000 0.1022000 0.02250000
## 2 0.1806667 0.1733556 0.1671778 0.1484222 0.1428778 0.1395111 0.03535556
## 3 0.1893143 0.1823143 0.1762571 0.1573857 0.1518286 0.1491857 0.03805714
## 4 0.0464000 0.0443000 0.0431000 0.0388000 0.0371000 0.0361000 0.01020000
## 5 0.4001333 0.3841667 0.3729000 0.3325667 0.3204333 0.3142667 0.07610000
## 6 0.1490800 0.1440400 0.1392800 0.1244400 0.1212800 0.1196800 0.03512000
## nm_1454 nm_1459 nm_1464 nm_1469 nm_1474 nm_1479
## 1 0.02340000 0.02290000 0.02290000 0.02160000 0.02380000 0.02430000
## 2 0.03740000 0.03788889 0.03773333 0.03604444 0.03916667 0.03972222
## 3 0.04005714 0.03981429 0.04022857 0.03771429 0.04222857 0.04300000
## 4 0.00980000 0.00930000 0.00940000 0.01070000 0.00980000 0.01010000
## 5 0.07976667 0.08240000 0.08286667 0.07683333 0.08650000 0.08673333
## 6 0.03746000 0.03722000 0.03710000 0.03504000 0.03890000 0.03954000
## nm_1484 nm_1489 nm_1494 nm_1499 nm_1504 nm_1509
## 1 0.02490000 0.02720000 0.02910000 0.03080000 0.03190000 0.03440000
## 2 0.04165556 0.04578889 0.04880000 0.05164444 0.05245556 0.05636667
## 3 0.04491429 0.04925714 0.05252857 0.05572857 0.05662857 0.06065714
## 4 0.00960000 0.01040000 0.01060000 0.01160000 0.01130000 0.01230000
## 5 0.09236667 0.10016667 0.10803333 0.11480000 0.11633333 0.12776667
## 6 0.04124000 0.04496000 0.04754000 0.05030000 0.05082000 0.05430000
## nm_1514 nm_1519 nm_1524 nm_1529 nm_1534 nm_1539
## 1 0.03490000 0.03670000 0.03750000 0.03920000 0.04030000 0.04160000
## 2 0.05882222 0.06085556 0.06241111 0.06476667 0.06682222 0.06802222
## 3 0.06407143 0.06647143 0.06902857 0.07158571 0.07348571 0.07591429
## 4 0.01340000 0.01380000 0.01430000 0.01430000 0.01460000 0.01510000
## 5 0.13163333 0.13730000 0.14216667 0.14716667 0.15250000 0.15653333
## 6 0.05730000 0.05946000 0.06168000 0.06358000 0.06510000 0.06676000
## nm_1544 nm_1549 nm_1554 nm_1559 nm_1564 nm_1569
## 1 0.04280000 0.04340000 0.04440000 0.04540000 0.04620000 0.04670000
## 2 0.07024444 0.07124444 0.07208889 0.07346667 0.07482222 0.07531111
## 3 0.07875714 0.08012857 0.08125714 0.08271429 0.08404286 0.08498571
## 4 0.01620000 0.01600000 0.01650000 0.01670000 0.01740000 0.01760000
## 5 0.16066667 0.16383333 0.16586667 0.16866667 0.17160000 0.17470000
## 6 0.06938000 0.07058000 0.07076000 0.07246000 0.07354000 0.07378000
## nm_1574 nm_1579 nm_1585 nm_1590 nm_1595 nm_1600
## 1 0.04680000 0.04800000 0.04900000 0.04920000 0.05000000 0.05270000
## 2 0.07537778 0.07751111 0.07878889 0.07894444 0.08146667 0.08364444
## 3 0.08481429 0.08802857 0.08922857 0.08968571 0.09214286 0.09394286
## 4 0.01760000 0.01780000 0.01860000 0.01840000 0.01900000 0.02040000
## 5 0.17400000 0.17870000 0.18240000 0.18273333 0.18763333 0.19306667
## 6 0.07350000 0.07644000 0.07726000 0.07740000 0.07976000 0.08172000
## nm_1605 nm_1610 nm_1615 nm_1620 nm_1625 nm_1630
## 1 0.05370000 0.05500000 0.05510000 0.05480000 0.05630000 0.05750000
## 2 0.08567778 0.08692222 0.08781111 0.08778889 0.09062222 0.09216667
## 3 0.09714286 0.09840000 0.09980000 0.09911429 0.10254286 0.10430000
## 4 0.02110000 0.02100000 0.02110000 0.02130000 0.02190000 0.02220000
## 5 0.19790000 0.20003333 0.20236667 0.20250000 0.20776667 0.21136667
## 6 0.08402000 0.08466000 0.08566000 0.08490000 0.08786000 0.08932000
## nm_1635 nm_1640 nm_1645 nm_1650 nm_1655 nm_1660
## 1 0.05660000 0.0579000 0.05790000 0.05900000 0.05830000 0.05900000
## 2 0.09185556 0.0915000 0.09266667 0.09321111 0.09345556 0.09431111
## 3 0.10390000 0.1035143 0.10494286 0.10522857 0.10637143 0.10731429
## 4 0.02240000 0.0227000 0.02250000 0.02320000 0.02330000 0.02320000
## 5 0.21226667 0.2102667 0.21440000 0.21520000 0.21540000 0.21853333
## 6 0.08880000 0.0883400 0.08982000 0.08980000 0.09088000 0.09164000
## nm_1665 nm_1670 nm_1675 nm_1680 nm_1685 nm_1690
## 1 0.05900000 0.05900000 0.05850000 0.05830000 0.05810000 0.05710000
## 2 0.09295556 0.09284444 0.09215556 0.09173333 0.09138889 0.09028889
## 3 0.10574286 0.10592857 0.10481429 0.10497143 0.10381429 0.10261429
## 4 0.02290000 0.02310000 0.02310000 0.02260000 0.02200000 0.02230000
## 5 0.21553333 0.21553333 0.21483333 0.21303333 0.21253333 0.21093333
## 6 0.09072000 0.09050000 0.08988000 0.08974000 0.08914000 0.08822000
## nm_1695 nm_1700 nm_1705 nm_1710 nm_1715 nm_1720
## 1 0.05610000 0.05550000 0.05440000 0.05300000 0.05360000 0.05160000
## 2 0.08888889 0.08704444 0.08623333 0.08433333 0.08383333 0.08166667
## 3 0.10084286 0.09887143 0.09774286 0.09560000 0.09518571 0.09295714
## 4 0.02120000 0.02090000 0.02170000 0.02110000 0.01970000 0.01920000
## 5 0.20663333 0.20236667 0.20073333 0.19583333 0.19496667 0.19100000
## 6 0.08706000 0.08558000 0.08470000 0.08334000 0.08320000 0.08138000
## nm_1725 nm_1730 nm_1735 nm_1740 nm_1745 nm_1750
## 1 0.04980000 0.04930000 0.04900000 0.04930000 0.04840000 0.04820000
## 2 0.07990000 0.07888889 0.07753333 0.07812222 0.07668889 0.07671111
## 3 0.09074286 0.08971429 0.08871429 0.08938571 0.08750000 0.08805714
## 4 0.01910000 0.01830000 0.01890000 0.01880000 0.01810000 0.01820000
## 5 0.18550000 0.18343333 0.18116667 0.18116667 0.17900000 0.17780000
## 6 0.07928000 0.07828000 0.07770000 0.07830000 0.07666000 0.07658000
## nm_1755 nm_1760 nm_1765 nm_1770 nm_1775 nm_1780
## 1 0.04570000 0.04670000 0.04510000 0.04350000 0.04200000 0.04160000
## 2 0.07482222 0.07445556 0.07201111 0.07078889 0.06730000 0.06630000
## 3 0.08547143 0.08454286 0.08157143 0.08045714 0.07618571 0.07557143
## 4 0.01790000 0.01730000 0.01710000 0.01790000 0.01630000 0.01600000
## 5 0.17330000 0.17243333 0.16686667 0.16336667 0.15710000 0.15436667
## 6 0.07514000 0.07432000 0.07190000 0.07100000 0.06746000 0.06700000
## nm_1785 nm_1790 nm_1960 nm_1965 nm_1970 nm_1975
## 1 0.04030000 0.04000000 0.01490000 0.01650000 0.01430000 0.01400000
## 2 0.06424444 0.06477778 0.02265556 0.02610000 0.02698889 0.02731111
## 3 0.07322857 0.07318571 0.01880000 0.02228571 0.02198571 0.02237143
## 4 0.01550000 0.01570000 0.00760000 0.00740000 0.00570000 0.00650000
## 5 0.14950000 0.15103333 0.03876667 0.04376667 0.04523333 0.04560000
## 6 0.06450000 0.06424000 0.01988000 0.02252000 0.02322000 0.02310000
## nm_1980 nm_1985 nm_1990 nm_1995 nm_2000 nm_2005
## 1 0.00000000 0.01510000 0.01730000 0.01540000 0.01800000 0.02250000
## 2 0.02805556 0.02861111 0.02923333 0.02888889 0.02997778 0.03581111
## 3 0.02422857 0.02485714 0.02514286 0.02474286 0.02758571 0.03372857
## 4 0.00740000 0.00660000 0.00650000 0.00690000 0.00920000 0.01060000
## 5 0.04800000 0.05023333 0.05270000 0.05240000 0.05403333 0.06260000
## 6 0.02492000 0.02590000 0.02586000 0.02550000 0.02758000 0.03460000
## nm_2010 nm_2015 nm_2020 nm_2025 nm_2030 nm_2035
## 1 0.01920000 0.01980000 0.01870000 0.01870000 0.01970000 0.01930000
## 2 0.03544444 0.03458889 0.03470000 0.03442222 0.03388889 0.03431111
## 3 0.03294286 0.03218571 0.03271429 0.03272857 0.03184286 0.03330000
## 4 0.01140000 0.01090000 0.00820000 0.00790000 0.00770000 0.00870000
## 5 0.06323333 0.06606667 0.06426667 0.06570000 0.06570000 0.06683333
## 6 0.03286000 0.03294000 0.03264000 0.03270000 0.03202000 0.03278000
## nm_2040 nm_2045 nm_2050 nm_2055 nm_2060 nm_2065
## 1 0.01950000 0.01930000 0.02060000 0.02100000 0.02060000 0.02040000
## 2 0.03455556 0.03498889 0.03530000 0.03616667 0.03457778 0.03574444
## 3 0.03357143 0.03447143 0.03515714 0.03654286 0.03531429 0.03672857
## 4 0.00900000 0.00820000 0.00760000 0.00840000 0.00830000 0.00990000
## 5 0.06886667 0.06960000 0.07216667 0.07380000 0.07043333 0.07506667
## 6 0.03352000 0.03380000 0.03470000 0.03552000 0.03472000 0.03552000
## nm_2070 nm_2075 nm_2080 nm_2085 nm_2090 nm_2095
## 1 0.02040000 0.02020000 0.02130000 0.01980000 0.02070000 0.01990000
## 2 0.03564444 0.03596667 0.03513333 0.03591111 0.03594444 0.03583333
## 3 0.03740000 0.03802857 0.03748571 0.03835714 0.03821429 0.03838571
## 4 0.00850000 0.00830000 0.00730000 0.00830000 0.00830000 0.00880000
## 5 0.07380000 0.07610000 0.07450000 0.07620000 0.07776667 0.07873333
## 6 0.03660000 0.03640000 0.03590000 0.03642000 0.03670000 0.03658000
## nm_2100 nm_2105 nm_2110 nm_2115 nm_2121 nm_2126
## 1 0.02100000 0.02120000 0.02070000 0.02150000 0.02180000 0.02240000
## 2 0.03610000 0.03595556 0.03666667 0.03664444 0.03737778 0.03772222
## 3 0.03940000 0.04002857 0.03958571 0.04055714 0.04155714 0.04210000
## 4 0.00870000 0.00830000 0.00780000 0.00870000 0.00910000 0.00840000
## 5 0.07933333 0.07933333 0.08056667 0.08086667 0.08330000 0.08423333
## 6 0.03786000 0.03780000 0.03752000 0.03818000 0.03942000 0.03956000
## nm_2131 nm_2136 nm_2141 nm_2146 nm_2151 nm_2156
## 1 0.02180000 0.02260000 0.02330000 0.02220000 0.02270000 0.02380000
## 2 0.03837778 0.03786667 0.03847778 0.03881111 0.03962222 0.03954444
## 3 0.04321429 0.04292857 0.04345714 0.04394286 0.04461429 0.04560000
## 4 0.00820000 0.00880000 0.00780000 0.01010000 0.00920000 0.00860000
## 5 0.08523333 0.08600000 0.08716667 0.08753333 0.08823333 0.09153333
## 6 0.04080000 0.04028000 0.04092000 0.04120000 0.04158000 0.04220000
## nm_2161 nm_2166 nm_2171 nm_2176 nm_2181 nm_2186
## 1 0.02380000 0.02430000 0.02360000 0.02430000 0.02590000 0.02420000
## 2 0.03981111 0.04061111 0.04077778 0.04131111 0.04107778 0.04164444
## 3 0.04527143 0.04557143 0.04695714 0.04720000 0.04721429 0.04762857
## 4 0.00950000 0.00940000 0.00900000 0.00910000 0.00910000 0.00970000
## 5 0.09013333 0.09173333 0.09296667 0.09466667 0.09503333 0.09506667
## 6 0.04208000 0.04254000 0.04396000 0.04300000 0.04366000 0.04364000
## nm_2191 nm_2196 nm_2201 nm_2206 nm_2211 nm_2216
## 1 0.02520000 0.02620000 0.02570000 0.02510000 0.02670000 0.02580000
## 2 0.04231111 0.04304444 0.04367778 0.04400000 0.04394444 0.04471111
## 3 0.04812857 0.04898571 0.05018571 0.04985714 0.05025714 0.05071429
## 4 0.00950000 0.01040000 0.00940000 0.00970000 0.01090000 0.01050000
## 5 0.09723333 0.09856667 0.09806667 0.10080000 0.10096667 0.10290000
## 6 0.04432000 0.04500000 0.04620000 0.04618000 0.04658000 0.04664000
## nm_2221 nm_2226 nm_2231 nm_2236 nm_2241 nm_2246
## 1 0.02580000 0.02580000 0.02590000 0.02560000 0.02630000 0.02380000
## 2 0.04512222 0.04430000 0.04420000 0.04327778 0.04145556 0.04091111
## 3 0.05105714 0.05074286 0.05065714 0.04912857 0.04802857 0.04725714
## 4 0.00970000 0.01070000 0.00980000 0.00890000 0.01060000 0.00950000
## 5 0.10100000 0.10160000 0.10173333 0.09840000 0.09653333 0.09426667
## 6 0.04706000 0.04658000 0.04664000 0.04536000 0.04438000 0.04362000
## nm_2251 nm_2256 nm_2261 nm_2266 nm_2271 nm_2276
## 1 0.02310000 0.02350000 0.02210000 0.02160000 0.02090000 0.02030000
## 2 0.03982222 0.03858889 0.03734444 0.03642222 0.03550000 0.03495556
## 3 0.04571429 0.04445714 0.04301429 0.04177143 0.04037143 0.04044286
## 4 0.00910000 0.00950000 0.00850000 0.00930000 0.00820000 0.00790000
## 5 0.09186667 0.08890000 0.08490000 0.08210000 0.08106667 0.07880000
## 6 0.04276000 0.04206000 0.04008000 0.03958000 0.03862000 0.03850000
## nm_2281 nm_2286 nm_2291 nm_2296 nm_2301 nm_2306
## 1 0.02080000 0.01970000 0.01980000 0.01940000 0.01920000 0.01850000
## 2 0.03422222 0.03354444 0.03256667 0.03201111 0.03168889 0.03151111
## 3 0.03830000 0.03828571 0.03665714 0.03612857 0.03555714 0.03460000
## 4 0.00860000 0.00810000 0.00750000 0.00740000 0.00740000 0.00860000
## 5 0.07580000 0.07560000 0.07363333 0.07110000 0.07043333 0.06886667
## 6 0.03668000 0.03738000 0.03538000 0.03458000 0.03418000 0.03372000
## nm_2311 nm_2316 nm_2321 nm_2326 nm_2331 nm_2336
## 1 0.01850000 0.01900000 0.01730000 0.01800000 0.01670000 0.01700000
## 2 0.03032222 0.03088889 0.03045556 0.03021111 0.02944444 0.02923333
## 3 0.03422857 0.03448571 0.03328571 0.03292857 0.03308571 0.03231429
## 4 0.00720000 0.00790000 0.00770000 0.00830000 0.00630000 0.00730000
## 5 0.06570000 0.06683333 0.06686667 0.06573333 0.06460000 0.06340000
## 6 0.03298000 0.03350000 0.03328000 0.03192000 0.03214000 0.03114000
## nm_2341 nm_2346 nm_2351 nm_2356 nm_2361 nm_2366
## 1 0.01590000 0.01590000 0.01830000 0.01610000 0.01530000 0.01620000
## 2 0.02911111 0.02870000 0.02763333 0.02763333 0.02813333 0.02681111
## 3 0.03145714 0.03085714 0.03032857 0.03042857 0.02878571 0.02852857
## 4 0.00690000 0.00660000 0.00680000 0.00700000 0.00710000 0.00720000
## 5 0.06103333 0.06156667 0.05810000 0.05810000 0.05833333 0.05723333
## 6 0.03066000 0.03050000 0.02978000 0.02996000 0.02898000 0.02756000
## nm_2371 nm_2376 nm_2381 nm_2386 nm_2391 nm_2396
## 1 0.01580000 0.01420000 0.01420000 0.01340000 0.01550000 0.01570000
## 2 0.02801111 0.02565556 0.02494444 0.02478889 0.02572222 0.02525556
## 3 0.02907143 0.02757143 0.02638571 0.02670000 0.02655714 0.02555714
## 4 0.00430000 0.00640000 0.00680000 0.00890000 0.00630000 0.00570000
## 5 0.05740000 0.05316667 0.04953333 0.05050000 0.05130000 0.05053333
## 6 0.02890000 0.02706000 0.02610000 0.02608000 0.02618000 0.02626000
## stems_flight1$taxonid
## 1 ABCO
## 2 ABCO
## 3 ABCO
## 4 ABCO
## 5 ABCO
## 6 ABCO
### check this out to see if it makes sense. For example, measured tree height vs. sampled tree height and compare w just using global buffer radius
# rename
names(sampled_points)[names(sampled_points)=="stems_flight1$taxonid"]<-"SOAP_ID"
ncol(sampled_points)
## [1] 360
# Machine or ensemble learning method. Can do both regression and classification tasks, and undertakes dimensional reduction methods, treats missing values, outlier values and other essential steps of data exploration. It is a type of ensemble learning method, where multiple CART models are combined
# Set a random seed so that results are reproducible next time we load the code - because this process has two sources of randomness (bagging for bootstrap aggregating takes subset of rows and only running subset of samples each time and subset of predictor variables (sqrt of those available))
set.seed(3693)
fit1 <- randomForest(as.factor(sampled_points$SOAP_ID) ~ .,
data=sampled_points,
importance=TRUE,
ntree=5000)
# ntree is number of trees to grow
# What variables were important?
varImpPlot(fit1)
Note that other packages process trees differently than randomForest.
## try rpart
library(rpart)
soap.rpart <- rpart(as.factor(sampled_points$SOAP_ID) ~ .,
data=sampled_points,
method="class")
printcp(soap.rpart)
##
## Classification tree:
## rpart(formula = as.factor(sampled_points$SOAP_ID) ~ ., data = sampled_points,
## method = "class")
##
## Variables actually used in tree construction:
## [1] nm_1539 nm_422 nm_452 nm_633
## [5] nm_693 nm_933 SOAP_lidarCHM SOAP_lidarSlope
## [9] SOAP_NDLI SOAP_PRI
##
## Root node error: 140/360 = 0.38889
##
## n= 360
##
## CP nsplit rel error xerror xstd
## 1 0.032143 0 1.00000 1.0000 0.066069
## 2 0.019048 2 0.93571 1.0571 0.066684
## 3 0.017857 5 0.87857 1.0214 0.066316
## 4 0.016071 9 0.80714 1.0643 0.066751
## 5 0.010000 13 0.74286 1.1357 0.067300
plot(soap.rpart)
text(soap.rpart)